import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router';
import { SinglepageService } from '../../service/singlepage.service';
import { Singlepage } from '../../model/singlepage';

@Component({
  selector: 'app-showlist',
  templateUrl: './showlist.component.html',
  styleUrls: ['./showlist.component.css']
})
export class ShowlistComponent implements OnInit {

  ss:Array<Singlepage>;
  selectedFile: string;
  constructor(
    private http:HttpClient,
    private routerinfo:ActivatedRoute,
    private router:Router,
    private singlepageService:SinglepageService

  ) { 
    this.ss=new Array();
  }

  ngOnInit() {
    this.loadSinglepageList();
  }

  private loadSinglepageList(){
    this.ss=new Array();
    this.singlepageService.getSinglepageList().
    then((data:any)=>{
           this.ss=data;
   
    })
  }

  addSinglepage(){
    this.router.navigate(['edit','add']);
  }

  editSinglepage(id:string){
    this.router.navigate(['edit',id]);
  }

  deleteSinglepage(id:string){
      this.singlepageService.deleteSinglepage(id).
      then((flag:boolean)=>{
        if(flag==true){
          this.loadSinglepageList();
        }
        else{
          alert("删除异常，请刷新后重试");
        }
      })
  }
}
